//
//  BasePageViewController.swift
//  ios_swift_demo1
//
//  Created by liutao on 2020/7/10.
//  Copyright © 2020 lt. All rights reserved.
//

import UIKit

//页面控制器 基类
class BasePageViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = UIColor.background
        
        if #available(iOS 11.0, *){
            UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
        }else{
            automaticallyAdjustsScrollViewInsets = false
        }
        
        // Do any additional setup after loading the view.
        setupLayout()
    }
    
    
    //在视图即将显示在屏幕上时调用
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        configNavigationBar()
        
    }
    
    
    func setupLayout(){}
    
    //自定义导航栏
    func configNavigationBar(){
        guard let navi = navigationController else { return }
        if navi.visibleViewController == self {
            navi.barStyle(.theme)
            navi.disablePopGesture = false
            navi.setNavigationBarHidden(false, animated: true)
            if navi.viewControllers.count > 1 {
                navigationItem.leftBarButtonItem  = UIBarButtonItem (image: UIImage(named: "nav_back_white"), style: .plain,target: self, action: #selector(self.pressBack))
            }
        }
    }
    
    //返回
    
    @objc func pressBack(){
        navigationController?.popViewController(animated: true)
    }
}


extension BasePageViewController {
    override var preferredStatusBarStyle: UIStatusBarStyle{
        return .lightContent
    }
}
